<?php include (dirname(__FILE__)."/include/header.php"); ?>
<?php 
	if($_REQUEST['method']=="logout"){
		unset($_SESSION['_shop']);
		unset($_SESSION['_user']);
		setcookie("id","");
		echo "<script>location.href='index.php';</script>";
	}
?>
 <?php 
	if($_REQUEST['method']=="login"){
	$mail=$_POST['mail'];
	$password=$_POST['password'];
	$sql="SELECT a.user_id,a.username,a.password,a.mail,a.integral,a.shop_id,a.remark,a.is_delete AS user_is_delete ,a.create_user AS user_create_user ,a.create_time AS user_create_time,a.update_user AS user_update_user,a.update_time AS user_update_time ,b.*  FROM zy_user a LEFT JOIN zy_shop b ON a.shop_id=b.shop_id WHERE a.`mail`='".$mail."' AND PASSWORD='".$password."' LIMIT 0,1";
	$result = mysql_query($sql);
	if($rs = mysql_fetch_array($result)){              
			if($rs['shop_id']==0){          
			$_SESSION['_user']=$rs;
			unset($_SESSION['_shop']);
			setcookie("id",$rs['user_id'],time()+3600*24*6);
			if($_REQUEST['gourl']!=""){
				if(strstr($_REQUEST['gourl'],"user_login.php")){
					 echo "<script>location.href='index.php';</script>";
				}else{
			echo "<script>location.href='".$_REQUEST['gourl']."'</script>";
				}
			}elseif($_REQUEST['url']!=""&&$_REQUEST['id']!=""){
				echo "<script>location.href='".$_REQUEST['url']."'</script>";
			
			}else{
			echo "<script>location.href='index.php';</script>";
			}
			}else{
			$_SESSION['_shop']=$rs;  
			unset($_SESSION['_user']);         
			echo "<script>location.href='shop/shop_management.php';</script>";
			}
	}else{                        //如果没有这个用户
		$error="Email或密码错误!";
	}
}
?>
  <div class="container">
    <div class="loginpage">
      <div class="loginpage_img"></div>
      <div class="round_box login_box" >
        <div class="wht"></div>
        <div class="content">
          <div id="tab">
            <ul>
              <li class="login_link_on"><a href="<?php echo SITE_ROOT;?>/user_login.php"><span>会员登录</span></a></li>
              <li class="reg_link_off"><a href="<?php echo SITE_ROOT;?>/user_registration.php"><span>免费注册</span></a></li>
            </ul>
          </div>
          <div id="login_form_div">
            <form id="login_form" name="login" method="post" action="user_login.php?method=login">
			<input name="gourl" value="<?php echo $_SERVER['HTTP_REFERER'];?>" type="hidden" />
              <div class="field_line" ><font color="red"><?php echo $error;?></font></div>
              <div class="field_line" >
                <div class="clear"></div>
              </div>
              <div class="field_line mbt5"> <span class="red">*</span> Email </div>
              <div class="field_line mbt5">
                <input name="mail" type="text" class="input_text" id="mail" />
              </div>
              <div class="field_line">
                <div class="clear"></div>
              </div>
              <div class="field_line mbt5"> <span class="red">*</span> 密码 </div>
              <div class="field_line mbt5">
                <input name="password" type="password"  class="input_text" id="password" />
              </div>
			 
              <div class="field_line input_login mbt5">
                 <span class="ml10"><a class="gray_link" href="javascript:void(0);" onclick="openwin()">忘记密码？</a></span> <span class="login_button_wrapper">
                <button type="submit" title="" name="submit" value="登录" post_click="登录中.." id="submit" class="f14 btn btn-yellow w75 h30 login_button p_r_login2 yellow_h30_w75_p20"> 登录</button>
                </span> </div>
            </form>
          </div>
          <div id="register_form_div" class="hidden"> </div>
          <div class="cl"></div>
        </div>
      </div>
      <div class="clear"></div>
    </div>
    <a id="back-to-top" href="javascript:void(0);">
    <div class="backtotop"></div>
    </a> 
   </div>
 <?php include (dirname(__FILE__)."/include/footer.php"); ?>
 <script type="text/javascript">
function openwin(){	
	if(navigator.appName=="Microsoft Internet Explorer"){	
		window.showModalDialog('forget_password.php','','dialogWidth=600px;dialogHeight=300px');	
	}
	else if(navigator.appName=="Netscape"){		
		window.open('forget_password.php','','width=600,height=300,modal=yes,location=no,status=no,toolbar=no,resizble=yes'); 
	}	
}

</script>
